package com.pengshun.modules.api.statistical.service.impl;

import com.pengshun.modules.api.coal.para.CoalParam;
import com.pengshun.modules.api.coal.result.CoalPriceDate;
import com.pengshun.modules.api.coal.result.CoalPriceEchartsResult;
import com.pengshun.modules.api.mapper.PsCoalMapper;
import com.pengshun.modules.api.mapper.SystemMapper;
import com.pengshun.modules.api.statistical.service.CoalStatisticalService;
import com.pengshun.modules.api.statistical.service.dto.CoalNewsPrice;
import com.pengshun.modules.api.statistical.service.dto.CoalStatisticalDto;
import com.pengshun.modules.api.statistical.service.dto.YearStatistical;
import com.pengshun.modules.api.system.service.dto.Content;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luoligang
 * @create 2021/1/25
 */
@Service
@RequiredArgsConstructor
public class CoalStatisticalServiceImpl implements CoalStatisticalService {


    private final PsCoalMapper coalMapper;

    private final SystemMapper systemMapper;

    @Override
    public BaseResult getCoalStatisticalList(PagePara dto) {
        List<CoalStatisticalDto> list = coalMapper.findAll(dto.getPage(), dto.getSize());
        return new BaseResult(0, list);
    }

    @Override
    public BaseResult detil(CoalParam dto) {
        if (dto.getType() == 6) {
            List<YearStatistical> yearStatisticals=coalMapper.selectYearStatisticals(dto.getCoalId());
            List<Content> colorList = systemMapper.selectBaseCategory("coal_color");
            int i=0;
            for (YearStatistical result:yearStatisticals){
                result.setColor(colorList.get(i).getValue());
                i++;
            }
            return new BaseResult(0,yearStatisticals);
        } else {
            List<CoalStatisticalDto> detils = coalMapper.selectCoalStatisticalDetil(dto.getCoalId(), dto.getType());
            YearStatistical yearStatistical=new YearStatistical();
            yearStatistical.setCoalStatisticalDtos(detils);
            return new BaseResult(0, yearStatistical);
        }
    }

    @Override
    public BaseResult getCoalNewPriceList(PagePara dto) {
        List<CoalNewsPrice> list=coalMapper.getCoalNewPriceList(dto.getPage(),dto.getSize());
        return new BaseResult(0,list);
    }
}
